package com.one.group.admin.service.impl;

import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.one.group.admin.mapper.SpUnitMapper;
import com.one.group.model.entity.SpUnit;
import com.one.group.model.vo.UnitManagementVo;
import com.one.group.service.SpUnitService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.format.annotation.DurationFormat;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@DubboService
public class SpUnitServiceImpl extends ServiceImpl<SpUnitMapper, SpUnit> implements SpUnitService {
    @Override
    public List<UnitManagementVo> mylist(Long buildingId) {
        //构建查询条件
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq(SpUnit::getBuildingId, buildingId);
        List<SpUnit> unitList = this.list(queryWrapper);
        List<UnitManagementVo> unitManagementVos = new ArrayList<>();
        for (SpUnit unit : unitList){
            UnitManagementVo unitManagementVo = new UnitManagementVo();
            unitManagementVo.setId(unit.getId());
            unitManagementVo.setName(unit.getName());
            unitManagementVos.add(unitManagementVo);
        }
        return unitManagementVos;
    }
}
